package com.datastructure.test.validtrianglenumber;

import java.util.Arrays;

public class ValidTriangleNumber {

    public int result = 0;
    public static void main(String[] args) {
        ValidTriangleNumber validTriangleNumber = new ValidTriangleNumber();
        int[] data = {2,3,4,4};
        validTriangleNumber.validTriangleNumber(data);
    }

    public int validTriangleNumber (int[] nums) {
        // write code here
        Arrays.sort(nums);
        for (int i = 0; i < nums.length-2; i++) {
            for(int j = i+1;j<nums.length-1;j++){
                for(int k = j+1;k<nums.length;k++){
                    if(judge(nums[k],nums[i],nums[j])){
                        result++;
                    }
                }
            }
        }
        return result;
    }

    private boolean judge(int num, int num1, int num2) {
        return num+num1>num2&&num+num2>num1&&num2+num1>num;
    }
}
